﻿using System;
using Jet.Dal.EF.Implementation.Contexts;

namespace Jet.Dal.EF.Implementation
{
	/// <summary>
	/// Implementation of IUnitOfWorkFactory for EF.
	/// </summary>
	public class EFUnitOfWorkFactory : IEFUnitOfWorkFactory
	{
		#region Private fields and consts


		private readonly string _connectionString;

		#endregion

		public EFUnitOfWorkFactory(string connectionString)
		{
			if (String.IsNullOrEmpty(connectionString))
			{
				throw new ArgumentNullException("connectionString");
			}
			_connectionString = connectionString;
		}

		#region Implementation of IEFUnitOfWorkFactory

		public IEFUnitOfWork CreateUoW<TEntity>(bool allowLazyLoading, bool allowProxyCreation) where TEntity : class
		{
			return new EFUnitOfWork(new DbContext1<TEntity>(_connectionString, allowLazyLoading, allowProxyCreation));
		}

		public IEFUnitOfWork CreateUoW<TEntity1, TEntity2>(bool allowLazyLoading, bool allowProxyCreation)
			where TEntity1 : class
			where TEntity2 : class
		{
			return new EFUnitOfWork(new DbContext2<TEntity1, TEntity2>(_connectionString, allowLazyLoading, allowProxyCreation));
		}

		public IEFUnitOfWork CreateUoW<TEntity1, TEntity2, TEntity3>(bool allowLazyLoading, bool allowProxyCreation)
			where TEntity1 : class
			where TEntity2 : class
			where TEntity3 : class
		{
			return new EFUnitOfWork(new DbContext3<TEntity1, TEntity2, TEntity3>(_connectionString, allowLazyLoading, allowProxyCreation));
		}

		public IEFUnitOfWork CreateUoW<TEntity1, TEntity2, TEntity3, TEntity4>(bool allowLazyLoading, bool allowProxyCreation)
			where TEntity1 : class
			where TEntity2 : class
			where TEntity3 : class
			where TEntity4 : class
		{
			return new EFUnitOfWork(new DbContext4<TEntity1, TEntity2, TEntity3, TEntity4>(_connectionString, allowLazyLoading, allowProxyCreation));
		}

		public IEFUnitOfWork CreateUoW<TEntity1, TEntity2, TEntity3, TEntity4, TEntity5>(bool allowLazyLoading, bool allowProxyCreation)
			where TEntity1 : class
			where TEntity2 : class
			where TEntity3 : class
			where TEntity4 : class
			where TEntity5 : class
		{
			return new EFUnitOfWork(new DbContext5<TEntity1, TEntity2, TEntity3, TEntity4, TEntity5>(_connectionString, allowLazyLoading, allowProxyCreation));
		}

		public IEFUnitOfWork CreateUoW<TEntity1, TEntity2, TEntity3, TEntity4, TEntity5, TEntity6>(
			bool allowLazyLoading, bool allowProxyCreation)
			where TEntity1 : class
			where TEntity2 : class
			where TEntity3 : class
			where TEntity4 : class
			where TEntity5 : class
			where TEntity6 : class
		{
			return new EFUnitOfWork(
				new DbContext6<TEntity1, TEntity2, TEntity3, TEntity4, TEntity5, TEntity6>(_connectionString, allowLazyLoading, allowProxyCreation));
		}

		public IEFUnitOfWork CreateUoW<TEntity1, TEntity2, TEntity3, TEntity4, TEntity5,
			TEntity6, TEntity7>(bool allowLazyLoading, bool allowProxyCreation)
			where TEntity1 : class
			where TEntity2 : class
			where TEntity3 : class
			where TEntity4 : class
			where TEntity5 : class
			where TEntity6 : class
			where TEntity7 : class
		{
			return
				new EFUnitOfWork(
					new DbContext7<TEntity1, TEntity2, TEntity3,
						TEntity4, TEntity5, TEntity6, TEntity7>(_connectionString, allowLazyLoading, allowProxyCreation));
		}

		public IEFUnitOfWork CreateUoW<TEntity1, TEntity2, TEntity3, TEntity4, TEntity5,
			TEntity6, TEntity7, TEntity8>(bool allowLazyLoading, bool allowProxyCreation)
			where TEntity1 : class
			where TEntity2 : class
			where TEntity3 : class
			where TEntity4 : class
			where TEntity5 : class
			where TEntity6 : class
			where TEntity7 : class
			where TEntity8 : class
		{
			return
				new EFUnitOfWork(
					new DbContext8<TEntity1, TEntity2, TEntity3,
						TEntity4, TEntity5, TEntity6, TEntity7, TEntity8>(_connectionString, allowLazyLoading, allowProxyCreation));
		}

		public IEFUnitOfWork CreateUoW<TEntity1, TEntity2, TEntity3, TEntity4, TEntity5,
			TEntity6, TEntity7, TEntity8, TEntity9>(bool allowLazyLoading, bool allowProxyCreation)
			where TEntity1 : class
			where TEntity2 : class
			where TEntity3 : class
			where TEntity4 : class
			where TEntity5 : class
			where TEntity6 : class
			where TEntity7 : class
			where TEntity8 : class
			where TEntity9 : class
		{
			return
				new EFUnitOfWork(
					new DbContext9<TEntity1, TEntity2, TEntity3, TEntity4,
						TEntity5, TEntity6, TEntity7, TEntity8, TEntity9>(_connectionString, allowLazyLoading, allowProxyCreation));
		}

		public IEFUnitOfWork CreateUoW
			<TEntity1, TEntity2, TEntity3, TEntity4, TEntity5,
			TEntity6, TEntity7, TEntity8, TEntity9, TEntity10>(bool allowLazyLoading, bool allowProxyCreation)
			where TEntity1 : class
			where TEntity2 : class
			where TEntity3 : class
			where TEntity4 : class
			where TEntity5 : class
			where TEntity6 : class
			where TEntity7 : class
			where TEntity8 : class
			where TEntity9 : class
			where TEntity10 : class
		{
			return
				new EFUnitOfWork(
					new DbContext10
						<TEntity1, TEntity2, TEntity3, TEntity4,
						TEntity5, TEntity6, TEntity7, TEntity8, TEntity9, TEntity10>(_connectionString, allowLazyLoading, allowProxyCreation));
		}

		public IEFUnitOfWork CreateUoW
			<TEntity1, TEntity2, TEntity3, TEntity4, TEntity5, TEntity6,
			TEntity7, TEntity8, TEntity9, TEntity10, TEntity11>(bool allowLazyLoading, bool allowProxyCreation)
			where TEntity1 : class
			where TEntity2 : class
			where TEntity3 : class
			where TEntity4 : class
			where TEntity5 : class
			where TEntity6 : class
			where TEntity7 : class
			where TEntity8 : class
			where TEntity9 : class
			where TEntity10 : class
			where TEntity11 : class
		{
			return
				new EFUnitOfWork(
					new DbContext11
						<TEntity1, TEntity2, TEntity3, TEntity4, TEntity5, 
						TEntity6, TEntity7, TEntity8, TEntity9, TEntity10, TEntity11>(
						_connectionString, allowLazyLoading, allowProxyCreation));
		}

		public IEFUnitOfWork CreateUoW
			<TEntity1, TEntity2, TEntity3, TEntity4, TEntity5, TEntity6, TEntity7,
			TEntity8, TEntity9, TEntity10, TEntity11, TEntity12>(bool allowLazyLoading, bool allowProxyCreation)
			where TEntity1 : class
			where TEntity2 : class
			where TEntity3 : class
			where TEntity4 : class
			where TEntity5 : class
			where TEntity6 : class
			where TEntity7 : class
			where TEntity8 : class
			where TEntity9 : class
			where TEntity10 : class
			where TEntity11 : class
			where TEntity12 : class
		{
			return
				new EFUnitOfWork(
					new DbContext12
						<TEntity1, TEntity2, TEntity3, TEntity4, TEntity5, 
						TEntity6, TEntity7, TEntity8, TEntity9, TEntity10, TEntity11,TEntity12>(
						_connectionString, allowLazyLoading, allowProxyCreation));
		}

		#endregion

	}
}
